/*
 * @Author: your name
 * @Date: 2021-05-28 09:42:20
 * @LastEditTime: 2021-08-20 17:43:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue3-template\src\main.ts
 */
import { createApp } from "vue";
import App from "./App.vue";
import "./registerServiceWorker";
import router from "./router";
import store from "./store";
import "@/assets/variable.less";
import localstorage from '@/utils/localstorage'
import './mockjs/index'

import Vant from 'vant';
import 'vant/lib/index.css';

router.beforeEach((to, from, next) => {
    // store.dispatch('onLoading', true);
    // console.log(store.state.isLoading);
    // let loginuser = localstorage.get("loginUser")
    let loginuser = localstorage.get("loginUser")
    if(loginuser && (loginuser as any).token){
        console.log("login start:", router)
        if(to.path == '/login'){
            router.push('/')
        }
    }else if(to.path != '/login'){
        router.push('/login')
    }
    console.log("---------------to , from:", to.path, from.path)
    if(to.path == '/login'){
        console.log("------")
        router.push('/')
    }else{
        next()
    }
});

router.afterEach((to, from) => {
    setTimeout(function() {
      // store.dispatch('onLoading', false);
      // console.log(store.state.isLoading);
    }, 1000);
});
  

let loginuser = localstorage.get("loginUser")
if(loginuser && (loginuser as any).token){
    console.log("login start:", router)
}else{
    //router.$push("/login")

    setTimeout(()=>{
        router.push('/login')
    }, 0)
    
}

let vapp = createApp(App)

vapp.use(Vant).use(store).use(router).mount("#app");
